package com.wang.quickhit;

import java.util.Random;

public class Game {
    public Player player;

    public Game() {
    }

    public Game(Player player) {
        this.player = player;
    }

    public Player getPlayer() {
        return player;
    }

    public void setPlayer(Player player) {
        this.player = player;
    }

    /**
     * 输出字符串，返回字符串与玩家的输入进行比较
     */

    public String printStr(){
        StringBuffer stu = new StringBuffer();
        Random r = new Random();
        int strLength = LevelParam.levels[player.getLevelNo() - 1].getStrLength();
        for (int i = 0; i < strLength; i++) {
            int randNum = r.nextInt(strLength);
            switch (randNum){
                case 0:
                    stu.append(">");
                    break;
                case 1:
                    stu.append("<");
                    break;
                case 2:
                    stu.append("#");
                    break;
                case 3:
                    stu.append("@");
                    break;
                case 4:
                    stu.append("%");
                    break;
                case 5:
                    stu.append("&");
                    break;
                case 6:
                    stu.append("*");
                    break;
            }
        }
        System.out.println(stu);
        return stu.toString();
    }

    public void printResult(String in, String out){
        if (out.equals(in)){
            long currentTime = System.currentTimeMillis();
            if ((currentTime - player.getStartTime()) / 1000 > LevelParam.levels[player.getLevelNo() - 1].getTimeLimit()){
                System.out.println("您输入的太慢，已超时，退出！");
                System.exit(1);
            }
            player.setCurScore(player.getCurScore() + LevelParam.levels[player.getLevelNo() - 1].getPerScore());
            player.setElapsedTime((int)((currentTime - player.getStartTime()) / 1000));
            System.out.println("输入正确，您的级别是：" + player.getLevelNo() + "，你的积分是：" + player.getCurScore() + "，用时：" + player.getElapsedTime());
            if (player.getLevelNo() == 6){
                int score = LevelParam.levels[player.getLevelNo() - 1].getPerScore() * (LevelParam.levels[player.getLevelNo() - 1].getStrTimes());
                if (score == player.getCurScore()){
                    System.out.println("恭喜您闯关成功！");
                    System.exit(0);
                }
            }
        } else {
            System.out.println("输入错误，退出！");
            System.exit(1);
        }
    }
}
